package com.microfch.m;

import java.util.ArrayList;
import java.util.List;

public class Topic {
    private final static char START ='[';
    private final static char END=']';
    private final String name;
    private List<Question> questionList = new ArrayList<>();
    private StringBuffer s = new StringBuffer();

    public String getName() {
        return name;
    }
    public Topic(){
        name = "无名";
    }

    public Topic(String s) {
        name = s;
    }

    public static String nameFromStr(String str) {
        int start = str.indexOf(START);
        int end = str.lastIndexOf(END);
        return str.substring(start+1,end);
    }

    public int getID() {
        return mID;
    }

    private int mID;

    public static boolean isTopic(String str) {
        int start = str.indexOf(START);
        if(start>=0 && str.lastIndexOf(END)>start+1)
            return true;
        else
            return false;
    }

    public void addQuestion(String str) {
        questionList.add(new Question(str,getID()));
    }

    public void setID(int id) {
        mID = id;
    }

    public List<Question>  getQuestList() {
        return questionList;
    }

    public int getAnswerCount() {
        int count=0;
        for (Question question : questionList) {
            if (question.getAnswer()) count++;
        }
        return  count;

    }
    public String getSugestion(){
        return s.toString();
    }

    public void addSuggestion(String str) {
        s.append(str+'\n');
    }
}
